import React from 'react';
import ReactDOM from 'react-dom';
import { HashRouter as Router, Route, Switch } from 'react-router-dom'
import { Provider } from 'mobx-react';
import { Tools } from 'weaver-mobile';
import allStore from './stores';
import './style';
import { QuickbarLayout, Home } from './components/home/export';
import { FloatingTouch } from 'weaver-mobile-page';
import { asyncComponent } from 'react-async-component';
const getLocaleLabel = Tools.getLocaleLabel.bind(this, 'govern_mobile');
const coms = {
  App: asyncComponent({
    resolve: () => import('./components/app')
  }),
  Home: asyncComponent({
    resolve: () => import('./components/home')
  }),
  QuickbarLayout: asyncComponent({
    resolve: () => import('./components/layout/quickbar/quickbarLayout')
  }),
  MobileLayout: asyncComponent({
    resolve: () => import('./components/mobileLayout')
  }),
  // Main: asyncComponent({ //����(���б�)����
  //   resolve: () => import('./components/main')
  // }),
}
//window.stores = allStore;

class Root extends React.Component {
  // constructor(props) {
  //   super(props);
  //   this.state={
  //     login: false
  //   }
  // }
  componentWillMount() {
    // const options2 = {
    //      method: 'POST',
    //      url: '/api/hrm/login/checkLogin',
    //      params: {
    //          loginid: 'wuxuan',
    //          userpassword:'1',
    //          logintype:1,
    //          islanguid:7,
    //          isie:false,
    //          ismobile: 1
    //      }
    //  };
    //  Tools.callApi(options2).then(re=>{
    //    if(re.loginstatus == 'true'){
    //      this.setState({
    //        login:true
    //      })
    //    }
    //  });
    window.useFloatingTouch = true;
  }

  onHomePageClick() {
    window.location.href = '#/pro/duty';
  }

  render() {
    //const height = document.body.clientHeigh;
    // if(this.state.login === false){
    //   return null
    // }else{
    return (
      <Provider {...allStore}>
        <Router>
          <FloatingTouch onClick={() => this.onHomePageClick()}>
            <Switch>
              {/* <Route name='app' path='/' onEnter={getLocaleLabel} component={coms.App}/> */}
              <Route exact path='/pro/duty' name='app' onEnter={getLocaleLabel} component={coms.Home} />
              <Route path='/mobile/Layout' name='app' onEnter={getLocaleLabel} component={coms.MobileLayout} />
              <Route path='/quickbar/:quicktype' render={(routerProps) => <coms.QuickbarLayout {...routerProps} />} />
              <Route path='/:tabType' name='tabType' render={() => (<coms.App />)} />
            </Switch>
          </FloatingTouch>
        </Router>
      </Provider>
    )
    //}
  }
}

ReactDOM.render(<Root />, document.getElementById('root'));
